package com.hnzq.cloud.controller;


import com.hnzq.cloud.entity.FreFlag;
import com.hnzq.cloud.model.Result;
import com.hnzq.cloud.param.UpdateFreFlagParam;
import com.hnzq.cloud.service.FreFlagService;
import org.aspectj.weaver.ast.Var;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jams
 * @since 2022-02-06
 */
@RestController
@RequestMapping("freFlag")
public class FreFlagController {

    @Resource
    private FreFlagService freFlagService;

    @PostMapping("addFreFlag")
    public Result addFreFlag(@RequestParam("flagName") String flagName){
        Boolean bool = freFlagService.addFreFlag(flagName);
        if (bool){
            return Result.newInstance().setMessage("新增成功");
        }else {
            return Result.newInstance().setMessage("新增失败").setCode(144);
        }
    }

    @DeleteMapping("deleteFreFlag")
    public Result deleteFreFlag(@RequestParam("id") Integer id){
        Boolean bool = freFlagService.deleteFreFlag(id);
        if (bool){
            return Result.newInstance().setMessage("删除成功");
        }else {
            return Result.newInstance().setMessage("删除失败").setCode(144);
        }
    }

    @GetMapping("findAllFreFlags")
    public Result findAllFreFlags(){
        List<FreFlag> allFreFlags = freFlagService.findAllFreFlags();
        return Result.newInstance().setMessage("查询成功").setData(allFreFlags);
    }

    @PutMapping("updateFreFlag")
    public Result updateFreFlag(@RequestBody UpdateFreFlagParam updateFreFlagParam){
        Boolean bool = freFlagService.updateFreType(updateFreFlagParam);
        if (bool){
            return Result.newInstance().setMessage("修改成功");
        }else {
            return Result.newInstance().setMessage("修改失败").setCode(144);
        }
    }
}

